import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path:'/',redirect: '/login'},
    {path: '/admin_manager', name: 'admin_manager',meta:{title:'后台管理'}, component: ()=> import('../views/AdminPage.vue'),children:[
        // {path: 'home', meta:{title:'Home测试数据页面'}, component: ()=> import('../views/Home.vue') },
        {path: 'test', meta:{title:'Test测试数据页面'},component: ()=> import('../views/Test.vue') },
        {path: 'data', meta:{title:'Data数据展示页面'},component: ()=> import('../views/Data.vue') },
        {path: 'user_information', meta:{title:'用户信息管理'},component: ()=> import('../views/UserManager/userInformation.vue') },
        {path: 'admin_information', meta:{title:'管理员信息管理'},component: ()=> import('../views/UserManager/adminInformation.vue') },
        {path: 'owner_information', meta:{title:'房东信息管理'},component: ()=> import('../views/UserManager/ownerInformation.vue') },
        {path: 'notice', meta:{title:'我的信息'},component: ()=> import('../views/informationManager/Notice.vue') },
        {path: 'room_information', meta:{title:'客房信息管理'},component: ()=> import('../views/informationManager/roomInformation.vue') },
        {path: 'room_type', meta:{title:'房间分类管理'},component: ()=> import('../views/informationManager/roomType.vue') },
        {path: 'check_in', meta:{title:'入住登记管理'},component: ()=> import('../views/informationManager/checkIn.vue') },
        {path: 'comments', meta:{title:'评论管理'},component: ()=> import('../views/informationManager/comments.vue') },
        {path: 'order', meta:{title:'订单管理'},component: ()=> import('../views/informationManager/order.vue') },
        {path: 'person', meta:{title:'个人信息'},component: ()=> import('../views/Person.vue') },
        {path: 'home', meta:{title:'首页'},component: ()=> import('../views/admin/Home.vue') },
        {path: 'room_image', meta:{title:'房间图片管理'},component: ()=> import('../views/informationManager/roomImage.vue') },
      ]},

      {path: '/owner_manager',name:'owner_manager',meta:{title:'房东管理页面'}, component: ()=> import('../views/OwnerPage.vue'),children:[
            {path: 'home', meta:{title:'首页'},component: ()=> import('../views/owner/Home.vue') },
            {path: 'house_information', meta:{title:'房源信息管理'},component: ()=> import('../views/UserManager/ownerInformation.vue') },
            {path: 'notice', meta:{title:'公告信息管理'},component: ()=> import('../views/informationManager/Notice.vue') },
            {path: 'room_information', meta:{title:'客房信息管理'},component: ()=> import('../views/informationManager/roomInformation.vue') },
            {path: 'room_type', meta:{title:'房间分类管理'},component: ()=> import('../views/informationManager/roomType.vue') },
            {path: 'check_in', meta:{title:'入住消息'},component: ()=> import('../views/informationManager/checkIn.vue') },
            {path: 'comments', meta:{title:'评论管理'},component: ()=> import('../views/informationManager/comments.vue') },
            {path: 'order', meta:{title:'订单管理'},component: ()=> import('../views/informationManager/order.vue') },
            {path: 'person', meta:{title:'个人信息'},component: ()=> import('../views/Person.vue') },
            {path:'appointment',meta: {title:'我的预约处理'},component: ()=> import('../views/front/MyAppointments.vue')}
        ]},

      {path: '/login',meta:{title:'登录页面'}, component: ()=> import('../views/Login.vue')},
      {path: '/register',meta:{title:'注册页面'}, component: ()=> import('../views/Register.vue')},

      {path: '/front_page',name: 'front_page',meta:{title:'前台页面'}, component: ()=> import('../views/Front.vue'),children:[
              {path: 'home', meta:{title:'首页'},component: ()=> import('../views/front/Home.vue') },
              {path: 'front_person', meta:{title:'个人信息'},component: ()=> import('../views/front/person.vue') },
              {path: 'collection',meta: {title:'我的收藏'},component: ()=> import('../views/front/Collection.vue')},
              {path:'appointment',meta: {title:'我的预约'},component: ()=> import('../views/front/MyAppointments.vue')},
              {path: 'notice', meta:{title:'我的信息'},component: ()=> import('../views/informationManager/Notice.vue') },
              {path: 'order', meta:{title:'我的订单'},component: ()=> import('../views/front/Order.vue') },
          ]},
      {path: '/room_detail/:roomId', name:'room_detail', meta:{title:'预订房间页面'}, component: () => import('../views/front/RoomDetail.vue')},
      {path: '/ws',meta:{title:'Websocket测试'}, component: () => import('../views/webSocketTest.vue')}




  ]
})

//判断用户是否登录
const isLogin = () => localStorage.getItem('token')!== null;

router.beforeEach( (to,from,next)  => {
    document.title = to.meta.title

    if (isLogin()|| to.path === '/login'||to.path === '/register'){
        next();
    }else {
        next('/login');
    }

})

export default router
